<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="../common/head.jsp" />
<title>编辑用户</title>
</head>
<body id="user-edit">
	<article class="page-container">
		<form action="" method="post" class="form form-horizontal" id="form-user">
			<input type="hidden" value="${user.id}" name="id">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="${user.username}" placeholder="" id="username" name="username" required="true" maxlength="30">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="${user.name}" placeholder="" id="name" name="name" required="true" maxlength="30">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box"> <select class="select" size="1" id="roleId" name="roleId" required="true">
							<option value="">请选择</option>
					</select> </span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="${user.tel }" placeholder="" id="tel" name="tel" required="true" isMobile="true" maxlength="30">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="${user.email }" placeholder="@" name="email" id="email" required="true" email="true" maxlength="50">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">备注：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<textarea name="remark" cols="" rows="" class="textarea" placeholder="说点什么..." onKeyUp="$.Huitextarealength(this,100)">${user.remark}</textarea>
					<p class="textarea-numberbar">
						<em class="textarea-length">0</em>/100
					</p>
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
		</form>
	</article>


</body>
<jsp:include page="../common/script.jsp" />
<script type="text/javascript">
	var $dom = $("#user-edit");
	var $form = $dom.find("#form-user");
	var $role = $dom.find("#roleId");

	var roleIdDefault = '${user.roleId}';

	$(function() {
		

		/**加载角色*/
		U.initSelect({
			url : "role/list.do",
			$dom : $role,
			callback : function() {
				if (roleIdDefault != '') {
					$role.val(roleIdDefault);
				}
			}
		});

		/**校验*/
		$form.validate({
			onkeyup : false,
			focusCleanup : true,
			success : 'valid',
			submitHandler : function(form) {
				var url;
				if(C.isEmpty(${user.id})){
					url="user/add.do";
				}else{
					url="user/update.do";
				}
				ajaxSubmit($form, url, function(_resp) {
					if (_resp.status == '000002') {
						U.alert(_resp.message);
						return;
					}
					//$(parent.document).find("#refresh").children().trigger("click");//此方法會刷新页面，体验不好
					U.msg('操作成功', 500, function() {
						var index = window.parent.layer.getFrameIndex(window.name);
						window.parent.load();
						window.parent.layer.close(index);
					});
				});
			}
		});

	});
</script>
</html>